package com.scfire.deviceInfo

import com.scfire.deviceInfoUtil.UserAgent

import grails.transaction.Transactional

import com.scfire.deviceInfoUtil.OperatingSystem

/** 
 * Copyright 2015 Shudao Info Tech Co. Ltd.  All rights reserved.
 * @author lhzeng
 * @email zenglh@haoshudao.com
 * @date 2015年6月7日 下午11:51:53 
 * @version V1.0
 */

class DeviceInfoService {
	
	def getDeviceInfo(String userAgent) {
		String device=""
		UserAgent useragent = new UserAgent(userAgent);
		//Mac系统和Linux系统当成pc设备处理
		if(
			useragent.getOperatingSystem().equals(OperatingSystem.MAC_OS)||
			useragent.getOperatingSystem().equals(OperatingSystem.MAC_OS_X) ||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_7)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_8)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_81)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_XP)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_98)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_VISTA)||
			useragent.getOperatingSystem().equals(OperatingSystem.WINDOWS_10)||
			useragent.getOperatingSystem().equals(OperatingSystem.LINUX)){
			device="pc"
		}else if(useragent.getOperatingSystem().equals(OperatingSystem.ANDROID4)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID4_TABLET)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID4_WEARABLE)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID3_TABLET)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID2)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID2_TABLET)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID1)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID_MOBILE)||
			useragent.getOperatingSystem().equals(OperatingSystem.ANDROID_TABLET) ||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS8_1_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS8_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS7_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS6_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS5_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.MAC_OS_X_IPAD)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS4_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS8_1_IPAD)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS8_IPAD)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS7_IPAD)||
			useragent.getOperatingSystem().equals(OperatingSystem.iOS6_IPAD)||
			useragent.getOperatingSystem().equals(OperatingSystem.MAC_OS_X_IPHONE)||
			useragent.getOperatingSystem().equals(OperatingSystem.MAC_OS_X_IPOD)){
			device="mobile"
		}else{
			device="pc"
		}
		return device
	}		
}
 